﻿using System.Linq;
using NUnit.Framework;

namespace CardGameFramework.Tests
{
    [TestFixture]
    class DeckTests
    {
        private Deck _instanceNoJokers;
        private Deck _instanceWithJokers;

        #region Setup and TearDown
        [SetUp]
        public void Setup()
        {
            _instanceNoJokers = new Deck();
            _instanceWithJokers = new Deck(includeJokers: true);
        }

        [TearDown]
        public void TearDown()
        {
            _instanceNoJokers = null;
            _instanceWithJokers = null;
        }
        #endregion

        #region Test Methods

        [Test]
        public void Ctor_NoJokersOneDeck_CountEquals52()
        {
            var expected = 52;
            var result = _instanceNoJokers.Count;
            Assert.AreEqual(expected, result);
        }


        [Test]
        public void Ctor_IncludeJokersOneDeck_CountEquals54()
        {
            var expected = 54;
            var result = _instanceWithJokers.Count;
            Assert.AreEqual(expected, result);
        }


        [Test]
        public void RemoveCard_RemoveTwoOfDiamonds_CardNotInDeck()
        {
            var card = new Card(Suits.Diamonds, Ranks.Two);
            _instanceNoJokers.RemoveAllCards(card);
            Assert.IsFalse(_instanceNoJokers.Values.Contains(card));
        }



        [Test]
        public void Ctor_NoJokersThreeDecks_CountCorrect()
        {
            var deck = new Deck(deckCount: 3);
            var expected = 52 * 3;
            var result = deck.Count;
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Ctor_IncludeJokersThreeDecks_CountCorrect()
        {
            var deck = new Deck(includeJokers: true, deckCount: 3);
            var expected = 54 * 3;
            var result = deck.Count;
            Assert.AreEqual(expected, result);
        }



        [Test]
        public void Ctor_ShuffledDeck_ContainsNoDuplicateCards()
        {
            var q = from card in _instanceNoJokers.Values
                    group card by card.Label into g
                    select g.Count();
            
            var c = from count in q
                    where count > 1
                    select count;
        
            Assert.AreEqual(0, c.Count());
        }

        
        #endregion
    }
}
